Control -  Loops Practice


Part A

Create a project (named in the usual way)  and in it a class with a main. 

Create a new class Meal representing a restaurant meal and give it instance variables for the name, the price, whether or not a drink is included, and an int for how spicy it is.

The toString should look something like

Salad (with drink) $4.99
or
Hamburger $7.99
or
Pork Vindaloo ***** (with drink) $13.77
or
Spicy Chicken Fingers ** $9.63
showing whether a drink is included, and with a number of stars for how spicy it is

Also give Meal a method totalPrice which prints the price, a 15% tip, and the total.

In the main, make sure this much works.


Part B

We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste

import java.util.Scanner;
As the first line inside your main method, paste
Scanner scan = new Scanner(System.in);
In order to read from the user, we use the Scanner like this:
int x = scan.nextInt(); // read an int
double d = scan.nextDouble(); // read a double
String s = scan.next(); // read a String
Ask the user to enter the information for meals or "QUIT" for the name of the meal if they want to stop. Don't accept negative prices or spiciness values (make them keep trying until they give good numbers). Then print the meal they entered, and show the total price. Don't get the rest of the info or print if they said they want to quit.

After the loop print both the most expensive meal and the spiciest meal you saw (it is okay if these turn out to be the same meal.) (NOT just the price or the spiciness, but the whole meal)

hint: your life will be easier if you re-create the meal each time through the loop using new, and use a separate string for the name/"QUIT" value, then copy into the meal's name (if it isn't "QUIT") instead of just reading directly into the name of the meal itself. You can have as many temporary variables inside methods as makes your life easier.